interface IRes {
  char: string
  length: number
}
// 方法1：嵌套循环
function findContinuousChar1 (str: string): IRes {
  const res: IRes = {
    char: '',
    length: 0
  }
  const length = str.length
  if (length === 0) return res
  let tempLength = 0 // 临时记录当前连续字符的长度
  // O(n)
  for (let i = 0; i < length; i++) {
    tempLength = 0 // 重置
    for (let j = i; j < length; j++) {
      if (str[i] === str[j]) {
        tempLength++
      }
      if (str[i] !== str[j] || j === length -1) {
        // 不相等，或者已经到了最后一个元素，要去判断最大值
        if (tempLength > res.length) {
          res.char = str[i]
          res.length = tempLength
        }
        if (i < length - 1) {
          i = j - 1 // 
        }
        break
      }
    }
  }
  return res
}

/**
 * 方法2：双指针
 * 定义指针i和j，j不动，i继续移动
 * 如果i和j的值一直相等，则i继续移动
 * 直到i和j的值不相等，记录处理，让j追上i，继续第一步
 */ 
function findContinuousChar2 (str: string): IRes {
  const res: IRes = {
    char: '',
    length: 0
  }
  const length = str.length
  if (length === 0) return res
  let tempLength = 0 // 临时记录当前连续字符的长度
  let i = 0
  let j = 0
  // O(n)
  for (; i < length; i++) {
    if (str[i] === str[j]) {
      tempLength++
    }
    if (str[i] !== str[j] || i === length - 1) {
      // 不相等，或者i到了字符串的末尾
      if (tempLength > res.length) {
        res.char = str[j]
        res.length = tempLength
      }
      tempLength = 0
      if (i < length - 1) {
        j = i // 让j“追上”i
        i--
      }
    }
    
  }
  return res
}